Vue.component('update', {
    template: `
		<el-dialog title="修改用户等级" width="1200px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="等级名称" prop="name">
							<el-input  v-model="form.name" autoComplete="off" clearable  placeholder="请输入等级名称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="等级名称(英文)" prop="e_name">
							<el-input  v-model="form.e_name" autoComplete="off" clearable  placeholder="请输入等级名称(英文)"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="等级名称(繁体)" prop="t_name">
							<el-input  v-model="form.t_name" autoComplete="off" clearable  placeholder="请输入等级名称(繁体)"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="等级级别" prop="level">
							<el-input type="number" v-model="form.level" autoComplete="off" required clearable  placeholder="请输入等级级别"></el-input>
							<small style="color: #C0C4CC">0:为默认等级,数字越大等级越大</small>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
                    <span>升级条件:</span>
                </el-row>
                <el-row >
					<el-col :span="24">
						<el-form-item label="USDT购买:">
                            <el-radio-group v-model="form.shop_pay">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="0">关闭</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="24">
                        <el-form-item label="支付金额:">
                            <el-input type="number" v-model="form.pay_amount" autoComplete="off" clearable  placeholder="请输入金额"></el-input>
                            <small style="color: #C0C4CC">可直接区块链购买等级(USDT)</small>
                        </el-form-item>
                    </el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="需要购买矿机:">
                            <el-radio-group v-model="form.pay_mining">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="2">关闭</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
                    <el-col :span="6">
                        <el-form-item label="直推:">
                            <el-radio-group v-model="form.push">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="0">关闭</el-radio>
							</el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="9">
                        <el-form-item label="直推人数:">
                            <el-input type="number" v-model="form.push_num" autoComplete="off" clearable  placeholder="请输入直推人数"></el-input>
                            <small style="color: #C0C4CC">直推人数等级为空时,人数限定.反则限制所需等级人数</small>
                        </el-form-item>
                    </el-col>
                    <el-col :span="9">
                        <el-form-item label="会员等级:">
                            <el-input type="number" v-model="form.push_level" autoComplete="off" clearable  placeholder="请输入直推会员等级id"></el-input>
                        </el-form-item>
                    </el-col>
				</el-row>
				<el-row >
					<el-col :span="6">
						<el-form-item label="间推:">
                            <el-radio-group v-model="form.interposition">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="0">关闭</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="间推人数:">
							<el-input type="number" v-model="form.interposition_num" autoComplete="off" clearable  placeholder="请输入间推人数"></el-input>
							<small style="color: #C0C4CC">间推人数等级为空时,人数限定.反则限制所需等级人数</small>
						</el-form-item>
					</el-col>
					<el-col :span="9">
						<el-form-item label="会员等级:">
							<el-input type="number" v-model="form.interposition_level" autoComplete="off" clearable  placeholder="请输入间推会员等级id"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="6">
						<el-form-item label="团队:">
                            <el-radio-group v-model="form.team">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="0">关闭</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="多线程:">
                            <el-radio-group v-model="form.team_thread">
								<el-radio :label="1">开启</el-radio>
								<el-radio :label="0">关闭</el-radio>
							</el-radio-group>
							<small style="color: #C0C4CC">需要多条直推线满足条件</small>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="团队人数:">
							<el-input type="number" v-model="form.team_num" autoComplete="off" clearable  placeholder="请输入团队人数"></el-input>
							<small class="Info">团队人数等级为空时,人数限定.反则限制所需等级人数</small>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="会员等级:">
							<el-input type="number" v-model="form.team_level" autoComplete="off" clearable  placeholder="请输入团队会员等级id"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
                <el-row v-if="team_computing">
				    <el-col :span="24">
						<el-form-item label="团队算力:">
							<el-input type="number" v-model="form.team_computing" autoComplete="off" clearable  placeholder="请输入团队算力"></el-input>
						</el-form-item>
					</el-col>
                </el-row>
				<div>
                    <span>升级奖励:</span>
                </div>
                <el-row>
				    <el-col :span="24">
						<el-form-item label="矿机极差:">
							<el-input type="number" v-model="form.mining_range" autoComplete="off" clearable  placeholder="请输入矿机极差"></el-input>
						</el-form-item>
					</el-col>
                </el-row>
                <el-row>
				    <el-col :span="24">
						<el-form-item label="矿机平级:">
							<el-input type="number" v-model="form.mining_peer" autoComplete="off" clearable  placeholder="请输入矿机平级"></el-input>
						</el-form-item>
					</el-col>
                </el-row>
				<el-row >
					<el-col :span="24" style="display: none">
						<el-form-item label="盲盒奖励:" >
							<el-input type="number" autoComplete="off" v-model="form.draw" clearable placeholder="请输入盲盒数量"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="全网分红" prop="status">
							<el-input type="number" autoComplete="off" v-model="form.weighted_dividend" clearable placeholder="请输入全网加权分红 %"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24" style="display: none">
						<el-form-item label="矩阵分红极差(%)" prop="matrix_team">
							<el-input type="number" autoComplete="off" v-model="form.matrix_team" clearable placeholder="请输入矩阵分红极差 %"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="每日代币奖励" prop="daily_reward_cid">
							<el-select style="width:100%" v-model="form.daily_reward_cid" filterable clearable placeholder="请选择奖励代币">
								<el-option v-for="(item,i) in lists" :key="i" :label="item.name" :value="item.id"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="每日代币奖励数量" prop="daily_num">
							<el-input type="number" autoComplete="off" v-model="form.daily_num" clearable placeholder="请输入每日奖励数量"/>
						</el-form-item>
					</el-col>
				</el-row>
				
				<el-row >
					<el-col :span="24">
						<el-form-item label="升级矿机算力(请选择LP)" prop="upgradation_cid">
							<el-select style="width:100%" v-model="form.upgradation_cid" filterable clearable placeholder="请选择奖励代币">
								<el-option v-for="(item,i) in lists" :key="i" :label="item.name" :value="item.id"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="升级矿机算力数量" prop="upgradation_num">
							<el-input type="number" autoComplete="off" v-model="form.upgradation_num" clearable placeholder="请输入每日奖励数量"/>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="限制KR兑换" prop="kr_limitation">
							<el-input type="number" autoComplete="off" v-model="form.kr_limitation" clearable placeholder="-"/>
							<small style="color: #C0C4CC">KR交易限制 -1:黑名单 0:不限制 大于0为具体限制数量</small>
						</el-form-item>
						
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="等级算力" prop="power">
							<el-input type="number" autoComplete="off" v-model="form.power" clearable placeholder="-"/>
							<small style="color: #C0C4CC">等级算力</small>
						</el-form-item>
						
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
			</div>
		</el-dialog>
	`,
    components:{
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'small'
        },
        info: {
            type: Object,
        },
    },
    data(){
        return {
            form: {
                name:'',
                e_name:'',
                t_name:'',
                level:'',
                matrix:2,
                pay_mining:2,
                push:0,
                push_num:'',
                push_level:'',
                interposition:0,
                interposition_num:'',
                interposition_level:'',
                team:0,
                team_thread:'',
                team_num:'',
                team_level:'',
                team_computing:'',
                draw:'',
                weighted_dividend:'',
                matrix_team:0,
                mining_peer:0,
                shop_pay:0,
                pay_amount:'',
                daily_reward_cid:0,
                daily_num:'',
                upgradation_cid:0,
                upgradation_num:0,
                power:0
            },
            lists:[],
            loading:false,
            team_computing:false,
            rules: {
                username:[
                    {required: true, message: '用户名不能为空', trigger: 'blur'},
                ],
                level:[
                    {required: true, message: '等级级别不能为空', trigger: 'blur'},
                ],
            }
        }
    },
    watch:{
        show(val){
            if(val){
                axios.post(base_url + '/Currency/available_currency').then(res => {
                    if(res.data.status == 200){
                        this.lists = res.data.data
                        this.form.vals = [];
                        this.lists.unshift({id:0,name:'无代币奖励'});
                        this.lists.forEach(item=>{
                            this.form.vals.push({id:item.id,name:item.name})
                        })
                    }
                })
            }
        }
    },
    methods: {
        open(){
            this.form = this.info
        },
        submit(){
            this.$refs['form'].validate(valid => {
                if(valid) {
                    this.loading = true
                    axios.post(base_url + '/MemberLevel/edit',this.form).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.$emit('refesh_list')
                            this.closeForm()
                        }else{
                            this.loading = false
                            this.$message.error(res.data.msg)
                        }
                    }).catch(()=>{
                        this.loading = false
                    })
                }
            })
        },
        closeForm(){
            this.$emit('update:show', false)
            this.loading = false
            if (this.$refs['form']!==undefined) {
                this.$refs['form'].resetFields()
            }
        },
    }
})
